﻿Public Class ClsTCurrencySumDbAccess
    Inherits ClsBaseDbAccess

    Public Sub New(ByVal s As String)
        MyBase.New(s, TABLE_NAME_T_CURRENCY_SUM)
    End Sub

    Public Sub New(ByVal s As String, ByVal n As String)
        MyBase.New(s, n)
    End Sub

    Public Function DeletCurrencySumByWorkPeriod(ByVal wp As String) As Integer

        Dim tmpRetInt As Integer

        Try

            Dim tmpSql As String
            Dim tmpParas(0) As OleDb.OleDbParameter

            Dim tmpDbAccess = GetConnection()

            '打开数据库
            tmpDbAccess.DbOpen()

            '构造查询语句
            tmpSql = "Delete * From [" & Me.AppTableName & "] "
            tmpSql &= " WHERE [WorkPeriod]=@WorkPeriod "

            tmpParas(0) = New OleDb.OleDbParameter("@WorkPeriod", OleDb.OleDbType.VarWChar)
            tmpParas(0).Value = wp

            tmpRetInt = tmpDbAccess.UpdateRecord(tmpSql, tmpParas)

            '关闭数据库
            tmpDbAccess.DbClose()

        Catch ex As OleDb.OleDbException

            mErrorNumber = ex.ErrorCode
            mErrorMessage = ex.Message
            mErrorCreater = "ClsTAccountSumDbAccess - DeleteAcctSumByWorkPeriod"

        End Try

        Return tmpRetInt

    End Function


    Public Overrides Function ConvertRecordToClass(reader As OleDb.OleDbDataReader) As Object

        If reader Is Nothing Then
            Return Nothing
        End If

        Dim tmpList As List(Of ClsTCurrencySum) = New List(Of ClsTCurrencySum)

        Try

            Dim tmpCls As ClsTCurrencySum

            While reader.Read()

                tmpCls = New ClsTCurrencySum()

                With tmpCls

                    .AcctSumId = reader.GetInt32(0)
                    .WorkPeriod = reader.GetString(1)
                    .AcctCode = reader.GetString(2)
                    .AcctLevel = reader.GetInt16(3)
                    .IfLastLevel = reader.GetBoolean(4)
                    .AcctName = reader.GetString(5)
                    .CreditSum = reader.GetDecimal(6)
                    .CreditSumCurrency = reader.GetDecimal(7)
                    .DebitSum = reader.GetDecimal(8)
                    .DebitSumCurrency = reader.GetDecimal(9)

                End With

                tmpList.Add(tmpCls)

            End While

        Catch ex As OleDb.OleDbException

            mErrorNumber = ex.ErrorCode
            mErrorMessage = ex.Message
            mErrorCreater = "ClsTCurrencySumDbAccess - ConvertRecordToClass"

        End Try

        Return tmpList

    End Function
End Class
